﻿using KinonekoSoftware.Foundation.Platform.Graphics;
using KinonekoSoftware.Foundation.UI.Core;
using KinonekoSoftware.UI;
using NLog;
using NLog.Config;
using NLog.Targets;

namespace KinonekoSoftware.Platform
{
    partial class NativeApplication
    {
        private bool _enableExceptionHandler;
        
        private static ILogger InstallLogger(ApplicationInformation ai, ForestSetting setting)
        {
            var config = new LoggingConfiguration();

            if (setting.EnableLogger)
            {
                var logfile = new FileTarget("logfile")
                {
                    FileName = ai.LogsFolder + "/${shortdate}.log",
                    Layout   = "${level} ${date:HH\\:mm\\:ss} | ${message}  ${exception} ${event-properties:myProperty}",
                };

                config.AddRule(LogLevel.Info, LogLevel.Fatal, logfile);

            }

            if (setting.EnableRuntimeLogger)
            {
                config.AddRule(LogLevel.Debug, LogLevel.Fatal, new TraceTarget());
            }

            var debugFileTarget = new DebuggerTarget
            {
                Layout = "【${level}】 ${date:HH\\:mm\\:ss} ${message}",
            };
            config.AddRule(LogLevel.Debug, LogLevel.Fatal, debugFileTarget);


            LogManager.Configuration = config;
            return LogManager.GetLogger("App");
        }
        
        
        #region InstallServices

        protected virtual void InstallServices()
        {

        }

        internal virtual void InstallServicesInternal()
        {
            Ioc.Use<IViewLocator, PlatformViewLocator>(new PlatformViewLocator());
            Ioc.Use<IBusyServiceEX, IBusyService, IBusyServiceAmbient, IDialogService, IDialogServiceAmbient, DialogService>(new DialogService());
            Ioc.Use<IPlatformImageProcessor, ImageProcessorImpl>(new ImageProcessorImpl());
            InstallServices();
        }
        
        

        #endregion
    }
}